package com.browsesoft.user;

import java.sql.SQLException;
import java.util.Hashtable;
import java.util.LinkedList;

import com.browsesoft.Manager;
import com.browsesoft.dbtools.DBTools;

/**
 * 已删除用户管理器
 */
public class DeletedUserManager implements Manager {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6563283470710811256L;

	/*
	 * 已删用户列表
	 */
	private LinkedList users = new LinkedList();

	public DeletedUserManager() {
	}

	/**
	 * 装载所有已经删除的用户
	 */
	public void load() throws Exception {
		String sql = "select * from t_deleteduser";
		try {
			String[][] deleteduser = DBTools.executeQueryWithTableHead(sql);
			if (deleteduser != null) {
				for (int i = 1; i < deleteduser.length; i++) {
					DeletedUser s = new DeletedUser(DBTools.getAttributes(
							deleteduser, i));
					// 将人员加入人员列表
					add(s);
				}
			}
		} catch (SQLException e) {
			System.out.println("从数据库表中装载删除用户错误，表名为：" + "t_deleteduser");
		}
	}

	/**
	 * 根据给定的ID号得到已删除用户
	 * 
	 * @param ID
	 */
	public Object getObject(String ID) {
		for (int i = 0; i < users.size(); i++) {
			DeletedUser deleteduser = (DeletedUser) users.get(i);
			String id = deleteduser.getAttributes().get("id").toString();
			if (id.equals(ID)) {
				return deleteduser;
			}
		}
		return null;
	}

	/**
	 * 从列表中删除一个已删用户
	 */
	public void remove(DeletedUser user) {
		users.remove(user);
	}

	/**
	 * 给列表中添加一个已删用户
	 */
	public void add(DeletedUser user) {
		users.add(user);
	}

	public void synchronAdd(String className, Hashtable attributes) {
		// TODO Auto-generated method stub

	}

	public void synchronRemove(String id) {
		// TODO Auto-generated method stub

	}

	public void synchronUpdate(String id, Hashtable attributes) {
		// TODO Auto-generated method stub

	}
}